{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a18bc7fc-c0bb-498d-8ac2-56b513645357",
   "metadata": {},
   "outputs": [],
   "source": [
    "from triton_trt_llm import HttpTritonClient"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6917492a-b287-422a-a787-38fd862339f8",
   "metadata": {},
   "source": [
    "#### Step 1: Structure the Query in a Prompt Template"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6bd40ebb-45bb-4a4b-b7b4-b6c726cd8ea7",
   "metadata": {},
   "outputs": [],
   "source": [
    "NEMOTRON_PROMPT_TEMPLATE = (\n",
    " \"\"\"<extra_id_0>System\n",
    "{system}\n",
    "<extra_id_1>User\n",
    "{prompt}\n",
    "<extra_id_1>Assistant\n",
    "\"\"\"\n",
    ")\n",
    "system = \"You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Please ensure that your responses are positive in nature.\"\n",
    "prompt = 'What is the fastest land animal?'\n",
    "prompt = NEMOTRON_PROMPT_TEMPLATE.format(prompt=prompt, system=system)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c0e7ec48-3865-4811-a175-6a6142240da2",
   "metadata": {},
   "source": [
    "#### Step 2: Create the Triton Client"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5b8476aa-6364-408a-840a-a8afb83ea08e",
   "metadata": {},
   "outputs": [],
   "source": [
    "triton_url = \"llm:8000\"\n",
    "client = HttpTritonClient(triton_url)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e9c89aca-1eae-4afc-b520-ed14ebef2606",
   "metadata": {},
   "outputs": [],
   "source": [
    "pload = {\n",
    "            'prompt':[[prompt]],\n",
    "            'tokens':64,\n",
    "            'temperature':1.0,\n",
    "            'top_k':1,\n",
    "            'top_p':0,\n",
    "            'beam_width':1,\n",
    "            'repetition_penalty':1.0,\n",
    "            'length_penalty':1.0\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0c32f8d8-f383-4faf-997a-1c8412412a5a",
   "metadata": {},
   "source": [
    "#### Step 3: Load the Model and Generate Response"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b02689bd-36d6-41fe-8636-9deeb52bc68f",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "model_name = \"ensemble\"\n",
    "client.load_model(model_name)\n",
    "val = client.request(model_name, **pload)\n",
    "print(val)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
